import java.awt.*;
public class demo {
    private  static  int  i=100;

    public static void main(String[] args) {
        demo1 a = new demo1("A");
        demo1 b = new demo1("B");

        a.start();
        b.start();
    }


    static class demo1 extends Thread{
        public demo1(String  target) {
            super(target);
        }

        @Override
        public void run() {
            while (i > 0) {
                synchronized (demo.class){
                    if (i>0){
                        i--;
                        System.out.println(this.getName()+"抢了一张票，还剩"+i+"张");
                    }
                }
//                try {
//                    this.sleep(3);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
            }



        }
    }

}
